package kook.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import kook.propeorties.OpenApiProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 控制台鉴权
 */
@Component
public class OpenApiInterceptor implements HandlerInterceptor {
    @Autowired
    private OpenApiProperties openApi;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        if (!openApi.getWhitelist().contains(request.getRemoteAddr())) {
            throw new RuntimeException();
        }
        return true;
    }
}
